package com.ruleengine.db.service.impl;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.toolkit.ChainWrappers;
import com.ruleengine.db.service.RuleengineService;
import com.ruleengine.db.mapper.RuleengineMapper;
import com.ruleengine.db.model.Ruleengine;

/**
 * @author lianghanwei on 2024/3/17
 */
@Service
public class RuleengineServiceImpl extends ServiceImpl<RuleengineMapper, Ruleengine> implements RuleengineService {

    private final RuleengineMapper ruleengineMapper;

    public RuleengineServiceImpl(RuleengineMapper ruleengineMapper) {
        this.ruleengineMapper = ruleengineMapper;
    }

    @Override
    public Ruleengine getRuleengine(String tenantId, String instanceId) {
        return ChainWrappers.lambdaQueryChain(ruleengineMapper)
            .eq(Ruleengine::getTenantId, tenantId)
            .eq(Ruleengine::getInstanceId, instanceId)
            .one();
    }

    @Override
    public boolean softDeleteRuleengine(String tenantId, String instanceId, String ruleengineId) {
        return ChainWrappers.lambdaUpdateChain(ruleengineMapper)
            .eq(Ruleengine::getTenantId, tenantId)
            .eq(Ruleengine::getInstanceId, instanceId)
            .eq(Ruleengine::getRuleengineId, ruleengineId)
            .remove();
    }
}
